#include "TimeIntegration.h"
using namespace Simulation;
// ----------------------------------------------------------------------------------------------
void TimeIntegration::semiImplicitEuler(const double h,
	const double mass, 
	glm::dvec3& position,
	glm::dvec3& velocity, 
	const glm::dvec3& acceleration)
{
	if (mass != 0.0)
	{
		velocity += acceleration * h;
		position += velocity * h;
	}
}


// ----------------------------------------------------------------------------------------------
void TimeIntegration::velocityUpdateFirstOrder(const double h, 
	const double mass,
	const glm::dvec3& position,
	const glm::dvec3& oldPosition, 
	glm::dvec3& velocity)
{
	if (mass != 0.0)
		velocity = (1.0 / h) * (position - oldPosition);
}


// ----------------------------------------------------------------------------------------------
void TimeIntegration::velocityUpdateSecondOrder(const double h, 
	const double mass,
	const glm::dvec3& position,
	const glm::dvec3& oldPosition,
	const glm::dvec3& positionOfLastStep, 
	glm::dvec3& velocity)
{
	if (mass != 0.0)
		velocity = (1.0 / h) * (1.5 * position - 2.0 * oldPosition + 0.5 * positionOfLastStep);
}